package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.Product;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuPrice;
import com.spzx.product.api.domain.vo.ProductSkuVo;
import com.spzx.product.api.domain.vo.SkuStockVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * ClassName: RemoteProductFallbackFactory
 * Package: com.spzx.product.api.factory
 * Description:
 */
@Component
@Slf4j
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    @Override
    public RemoteProductService create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());

        return new RemoteProductService() {
            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                return R.fail("获取商品sku失败"+cause.getMessage());
            }

            @Override
            public R<Product> getProduct(Integer id, String source) {
                return R.fail("获取商品失败"+cause.getMessage());
            }

            @Override
            public R<SkuPrice> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品sku价格失败"+cause.getMessage());
            }

            @Override
            public R<SkuStockVo> getSkuStock(Long skuId, String source) {
                return R.fail("获取商品sku库存失败"+cause.getMessage());
            }

            @Override
            public R<Map<String, Long>> getSkuSpecValue(Long id, String source) {
                return R.fail("获取商品sku规格值失败"+cause.getMessage());
            }

            @Override
            public R<List<String>> getProductDetails(Long id, String source) {
                return R.fail("获取商品sku图片详情失败"+cause.getMessage());
            }

            @Override
            public R<List<SkuPrice>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("获取商品sku价格列表失败"+cause.getMessage());
            }


        };
    }
}
